<script setup>
import { CalendarDays } from 'lucide-vue-next'

const { article } = defineProps({
  article: {
    type: Object,
    required: true,
  },
})
</script>

<template>
  <article class="article-card">
    <div class="cover">
      <img :src="article.coverImage" alt="Article cover image" />
    </div>
    <div class="info">
      <h2 class="title">
        {{ article.title }}
      </h2>
      <div class="additional-info">
        <div class="left">
          <CalendarDays class="date-icon" />
          <span>{{ article.createdAt }}</span>
        </div>
        <div class="right">
          <span class="category">{{ article.category.name }}</span>
        </div>
      </div>
      <p class="summary">
        {{ article.summary }}
      </p>
    </div>
  </article>
</template>

<style lang="scss" scoped>
.article-card {
  background-color: var(--color-surface);
  border-radius: 16px;
  overflow: hidden;
  transition: box-shadow $transition-speed;
  cursor: pointer;

  &:hover {
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  }

  .cover {
    height: 220px;
    overflow: hidden;

    img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      transition: transform $transition-speed;
    }
  }

  .info {
    padding: 20px;

    .title {
      font-size: 20px;
      font-weight: 700;
      line-height: 1.4;
      margin-bottom: 12px;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 2;
      line-clamp: 2;
      overflow: hidden;
      color: var(--color-text);
    }

    .additional-info {
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-bottom: 12px;

      .left {
        display: flex;
        align-items: center;
        gap: 6px;
        font-size: 14px;
        color: var(--color-gray-2);

        .date-icon {
          width: 16px;
          height: 16px;
        }
      }

      .right {
        .category {
          padding: 4px 12px;
          background-color: var(--color-primary);
          color: var(--color-light);
          font-size: 13px;
          font-weight: 600;
          border-radius: 20px;
          transition: background-color $transition-speed;
        }
      }
    }

    .summary {
      font-size: 15px;
      line-height: 1.6;
      color: var(--color-gray-1);
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 2;
      line-clamp: 2;
      overflow: hidden;
    }
  }
}

@media (min-width: 768px) {
  .article-card {
    display: flex;
    flex-direction: row;

    .cover {
      width: 280px;
      height: auto;
      max-height: 210px;
    }

    .info {
      flex: 1;
      padding: 24px;

      .title {
        font-size: 22px;
      }

      .summary {
        font-size: 16px;
      }
    }
  }
}

@media (min-width: 1024px) {
  .article-card {
    .cover {
      width: 320px;
    }
  }
}
</style>
